package com.linkhouse.controller;

import com.linkhouse.common.domain.Result;
import com.linkhouse.domain.bo.TbUserBO;
import com.linkhouse.domain.dto.TbUserDTO;
import com.linkhouse.service.TbUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RequestMapping("tbUser")
@RestController
@Api("用户中心")
public class TbUserController {

    @Autowired
    private TbUserService tbUserService;

    //通过用户id,查询用户信息
    @GetMapping("/{id}")//GET
    @ApiOperation("根据id查询用户信息")
    @ApiImplicitParam(name="id",value = "用户id",required = true,paramType = "path")
    public Result query(@PathVariable("id") Long id){
        //判断用户有没有登录,有就执行,没有就让用户登录
        TbUserBO tbUserBO = tbUserService.query(id);
        return Result.ok().setData(tbUserBO);
    }

        //通过用户id,修改用户信息(用户名,手机号,密码,注销)
    @PutMapping
    @ApiOperation("根据用户id,修改用户信息")
    @ApiImplicitParam(name = "tbUserDTO",value = "实体类",required = true,paramType = "body")
    public Result updatephone(@RequestBody TbUserDTO tbUserDTO){
        //判断用户有没有登录,有就执行,没有就让用户登录

        TbUserBO tbUserBO = new TbUserBO();
        BeanUtils.copyProperties(tbUserDTO,tbUserBO);

        tbUserService.updatephone(tbUserBO);
        return Result.ok();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据用户id,删除")
    @ApiImplicitParam(name = "id",value = "用户id",required = true,paramType = "body")
    public Result delete(@PathVariable("id") Long id){
        //判断用户有没有登录,有就执行,没有就让用户登录

        tbUserService.delete(id);
        return Result.ok();
    }

}
